package cn.com.dhcc.app.pub.module.logmgr.controller;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.dhcc.app.core.annotation.CoreMenuCode;
import cn.com.dhcc.app.core.annotation.CoreMenuCode.CORE_LEAF_MENU;
import cn.com.dhcc.app.core.base.BaseController;
import cn.com.dhcc.app.core.base.log.LogType;
import cn.com.dhcc.app.core.component.log.Log;
import cn.com.dhcc.app.core.component.pager.Pager;
import cn.com.dhcc.app.core.component.pager.PagerData;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.para.ComponentPara.LOG;
import cn.com.dhcc.app.core.util.StrUtil;
import cn.com.dhcc.app.pub.module.logmgr.service.LogMgrService;
import cn.com.dhcc.app.pub.module.logmgr.vo.LogBean;
/**
 * 通用日志管理
 * @author qiao
 * @2015-7-6 @下午3:01:32
 */
@Controller
@RequestMapping("/pub/sysmgr/logmgr")
@CoreMenuCode(belongToMenu=CORE_LEAF_MENU.LOG_MGR)
public class LogMgrController extends BaseController{

	@Autowired
	private LogMgrService logMgrService;
	private static Logger logger = Log.getLogger(LogType.BUSILOG);
	@RequestMapping("/list")
	public String list(HttpSession httpSession,Model model, LogBean logBean,Pager pager){
		try {
			if(!LOG.LOG_TO_DB_ENABLE||StrUtil.isBlank(LOG.LOG_TODB_TABLE)){
				return toAlertPage(model, "未启动日志组件或参数配置错误！");
			}
			PagerData<LogBean> pagerData = logMgrService.getLogList(httpSession,logBean, pager);
			model.addAttribute("logs", pagerData.getDatas());
			setTotoal(model, pagerData.getTotal());
		} catch (ServiceException e) {
			logger.error("获取日志列表失败", e);
			return toAlertPage(model, "获取日志列表失败");
		}
		return "/pub/sysmgr/logmgr/log_list";
	}
}
